// import type { FormListContext, ProForm } from '@alipay/tech-ui';
import type { Form } from "antd";
import { createContext } from "react";
import type { NamePath } from "../types";
import type { Locale } from "../locale";
import { noop } from "../utils";
import type { RuleTreeProps } from "./RuleTree";

export interface ConfigProviderProps {
  /** 设置统一样式前缀，默认为空 */
  prefixCls?: string;
  /** 国际化配置 */
  locale?: Locale;
  /** pro-components FormListContext */
  // FormListContext?: typeof FormListContext;
  rootPath?: NamePath;
  /** 兼容云凤蝶应用 */
  __components?: {
    Form: typeof Form;
    // ProForm?: typeof ProForm;
  };
}

export const RuleTreeContext = createContext<ConfigProviderProps>({});

/** 全局化配置 */
export function ConfigProvider(
  props: {
    children: React.ReactNode;
  } & Partial<
    Omit<React.ContextType<typeof RuleTreeContext>, "FormListContext">
  >
) {
  const { children, ...restProps } = props;
  return (
    <RuleTreeContext.Provider value={restProps}>
      {children}
    </RuleTreeContext.Provider>
  );
}

type PropsKeys =
  | "children"
  | "onChange"
  | "max"
  | "maxDeepth"
  | "gap"
  | "createRender"
  | "disabled"
  | "actionRender"
  | "itemRender"
  | "dragLayerRender"
  | "relationRender"
  | "defaultRelationValue"
  | "onRelationChange"
  | "relationFormItemProps"
  | "relationFormItemRender"
  | "nodeRender"
  // | 'resultRender'
  | "draggable";

export const RuleTreePropsContext = createContext<
  Pick<RuleTreeProps, PropsKeys> & { uid: string }
>({
  children: noop,
  onChange: undefined,
  onRelationChange: undefined,
  max: undefined,
  maxDeepth: undefined,
  gap: [32, 24],
  createRender: undefined,
  disabled: undefined,
  actionRender: undefined,
  itemRender: undefined,
  dragLayerRender: undefined,
  nodeRender: undefined,
  relationRender: undefined,
  relationFormItemProps: undefined,
  relationFormItemRender: undefined,
  defaultRelationValue: undefined,
  // resultRender: undefined,
  draggable: undefined,
  uid: "",
});

/** 空的Context */
export const NoopContext = createContext<any>({});
